package br.com.hotel.conexao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;

public class Conexao implements InterfaceConexao {
	
	private String url;
	private String driver;
	private String usuario;
	private String senha;
	private ResourceBundle config;
	
	public Conexao(){
		config = ResourceBundle.getBundle("br.com.hotel.conexao.bancodedados");
		this.url = config.getString("url");
		this.driver = config.getString("driver");
		this.usuario = config.getString("usuario");
		this.senha = config.getString("senha");
	}
		

	private Connection con = null;
	
	public Connection conectar(){
		
		try {
			Class.forName(driver);
			con = DriverManager.getConnection(url, usuario, senha);
			
		} catch (ClassNotFoundException e) {
			System.out.println("Erro na classe! "+e);
		} catch(SQLException ex){
			System.out.println("Erro na conexao! "+ex);
		}
		
		return con;
		
	}
	
	public void desconectar(){
		try {
			con.close();
		} catch (SQLException e) {
			System.out.println("Erro ao desconectar! ");
			e.printStackTrace();
		}
	}
}
